package com.ttg.web.controller.common;

import com.ttg.common.entities.BasePage;
import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.dto.CMReportDTO;
import com.ttg.model.dto.CMReportYearMonthDTO;
import com.ttg.model.dto.QualityManageRuleListDTO;
import com.ttg.web.service.CostManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * Description： 成本管理
 * Author: chenyou
 * Date: 2025/9/11 9:51
 * Company: ttg
 * Copyright: Copyright (c) 2025
 */
@Slf4j
@Api("成本管理")
@RestController
@RequestMapping("/cost/manage")
public class CostManagementController {

    @Autowired
    private CostManageService costManageService;

    @ApiOperation("行业/商户存贷信息-可选年份列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimType",value = "维度类型",required = true,dataType = "integer",paramType = "form",example = "0-商户维度，1-行业维度"),
            @ApiImplicitParam(name = "year",value = "报告所属年",required = true,dataType = "string",paramType = "form",example = "2025"),
    })
    @RequestMapping("/depositSelectYears")
    public BaseResult depositSelectYears(@RequestBody(required = false) String data){
        CMReportYearMonthDTO reqDto = RequestParamsManager.transformRequestParam(data, CMReportYearMonthDTO.class);
        return BaseResult.success(costManageService.depositSelectYears(reqDto));
    }

    @ApiOperation("行业/商户存贷信息-可选月份列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimType",value = "维度类型",required = true,dataType = "integer",paramType = "form",example = "0-商户维度，1-行业维度"),
            @ApiImplicitParam(name = "year",value = "报告所属年",required = true,dataType = "string",paramType = "form",example = "2025"),
    })
    @RequestMapping("/depositSelectMonths")
    public BaseResult depositSelectMonths(@RequestBody(required = false) String data){
        CMReportYearMonthDTO reqDto = RequestParamsManager.transformRequestParam(data, CMReportYearMonthDTO.class);
        return BaseResult.success(costManageService.depositSelectMonths(reqDto));
    }

    @ApiOperation("行业存贷信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimType",value = "维度类型",required = true,dataType = "integer",paramType = "form",example = "0-商户维度，1-行业维度"),
            @ApiImplicitParam(name = "year",value = "报告所属年",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "month",value = "报告所属月",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "clsId1",value = "行业一级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clsId2",value = "行业二级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "totalMctCountLowerBound",value = "总商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "activeMctCountLowerBound",value = "活跃商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clearCostLowerBound",value = "清算成本下限值",required = true,dataType = "BigDecimal",paramType = "form"),
            @ApiImplicitParam(name = "activeDayLowerBound",value = "活跃天数下限值",required = true,dataType = "integer",paramType = "form"),
    })
    @RequestMapping("/industryDeposit")
    public BaseResult industryDeposit(@RequestBody(required = false) String data){
        CMReportDTO reqDto = RequestParamsManager.transformRequestParam(data, CMReportDTO.class);
        return BaseResult.success(costManageService.industryDeposit(reqDto));
    }

    @ApiOperation("行业存贷信息下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimType",value = "维度类型",required = true,dataType = "integer",paramType = "form",example = "0-商户维度，1-行业维度"),
            @ApiImplicitParam(name = "year",value = "报告所属年",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "month",value = "报告所属月",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "clsId1",value = "行业一级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clsId2",value = "行业二级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "totalMctCountLowerBound",value = "总商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "activeMctCountLowerBound",value = "活跃商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clearCostLowerBound",value = "清算成本下限值",required = true,dataType = "BigDecimal",paramType = "form"),
            @ApiImplicitParam(name = "activeDayLowerBound",value = "活跃天数下限值",required = true,dataType = "integer",paramType = "form"),
    })
    @RequestMapping("/industryDepositDownload")
    public void industryDepositDownload(@RequestBody(required = false) String data, HttpServletResponse response){
        CMReportDTO reqDto = RequestParamsManager.transformRequestParam(data, CMReportDTO.class);
//        reqDto.setYear("2025");
//        reqDto.setMonth("06");
//        reqDto.setDimType(1);
//        reqDto.setClsId1(1);
//        reqDto.setClsId2(11);
        costManageService.industryDepositDownload(reqDto,response);
    }

    @ApiOperation("商户存贷信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimType",value = "维度类型",required = true,dataType = "integer",paramType = "form",example = "0-商户维度，1-行业维度"),
            @ApiImplicitParam(name = "year",value = "报告所属年",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "month",value = "报告所属月",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "clsId1",value = "行业一级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clsId2",value = "行业二级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "totalMctCountLowerBound",value = "总商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "activeMctCountLowerBound",value = "活跃商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clearCostLowerBound",value = "清算成本下限值",required = true,dataType = "BigDecimal",paramType = "form"),
            @ApiImplicitParam(name = "activeDayLowerBound",value = "活跃天数下限值",required = true,dataType = "integer",paramType = "form"),
    })
    @RequestMapping("/merchDeposit")
    public BaseResult merchDeposit(@RequestBody(required = false) String data){
        CMReportDTO reqDto = RequestParamsManager.transformRequestParam(data, CMReportDTO.class);
        return BaseResult.success(costManageService.merchDeposit(reqDto));
    }

    @ApiOperation("商户存贷信息下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimType",value = "维度类型",required = true,dataType = "integer",paramType = "form",example = "0-商户维度，1-行业维度"),
            @ApiImplicitParam(name = "year",value = "报告所属年",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "month",value = "报告所属月",required = true,dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "clsId1",value = "行业一级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clsId2",value = "行业二级分类",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "totalMctCountLowerBound",value = "总商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "activeMctCountLowerBound",value = "活跃商户数下限值",required = true,dataType = "integer",paramType = "form"),
            @ApiImplicitParam(name = "clearCostLowerBound",value = "清算成本下限值",required = true,dataType = "BigDecimal",paramType = "form"),
            @ApiImplicitParam(name = "activeDayLowerBound",value = "活跃天数下限值",required = true,dataType = "integer",paramType = "form"),
    })
    @RequestMapping("/merchDepositDownload")
    public void merchDepositDownload(@RequestBody(required = false) String data, HttpServletResponse response){
        CMReportDTO reqDto = RequestParamsManager.transformRequestParam(data, CMReportDTO.class);
//        reqDto.setYear("2025");
//        reqDto.setMonth("06");
//        reqDto.setDimType(0);
        costManageService.merchDepositDownload(reqDto,response);
    }


}
